package org.administer.contaroller;

import org.administer.dao.CrmPermissionDao;
import org.administer.pojo.CrmPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private CrmPermissionDao crmPermissionDao;

    @RequestMapping("/parentList")
    @ResponseBody
    public List<CrmPermission> parentList(){
        return crmPermissionDao.getParentPers();
    }
    @RequestMapping("/index")
    public String index() throws Exception{
        return "permission/index";
    }
    @RequestMapping("/list")
    @ResponseBody
    public Map<String,Object> list() throws Exception {
        Map<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("msg",null);
        map.put("data",crmPermissionDao.getAll());
        return map;
    }
    @RequestMapping("/add")
    @ResponseBody
    public Map<String,Object> add(CrmPermission crmPermission) throws Exception {
        Map<String,Object> map = new HashMap<>();
        crmPermissionDao.add(crmPermission);
        return map;
    }
    @RequestMapping("/del")
    @ResponseBody
    public Map<String,Object> del(int id) throws Exception {
        Map<String,Object> map = new HashMap<>();
        crmPermissionDao.del(id);
        return map;
    }
    @RequestMapping("/update")
    @ResponseBody
    public Map<String,Object> update(CrmPermission crmPermission) throws Exception {
        Map<String,Object> map = new HashMap<>();
        crmPermissionDao.update(crmPermission);
        return map;
    }
    @RequestMapping("/addmenu")
    @ResponseBody
    public Map<String,Object> addmenu(CrmPermission crmPermission) throws Exception {
        Map<String,Object> map = new HashMap<>();
        crmPermissionDao.addmenu(crmPermission);
        return map;
    }
    @RequestMapping("/getzi")
    @ResponseBody
    public  Map<String,Object> deletezi(Integer id)throws  Exception {
        Map<String, Object> map = new HashMap<>();
        List<CrmPermission> permissionList = crmPermissionDao.getzi(id);
        if (permissionList.size() > 0) {
            map.put("code", 1);
            return map;
        }
        map.put("code", 0);
        return map;
    }
}
